﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public partial class bzService_Down : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string q1 = Request.QueryString["q1"];

        string SqlComm = string.Format(@"
             select * from tb810310 where fileid = {0}
        ", q1);

        DataSet ds = DbObject.ExecuteDataset(DbObject.CONN_STRING, CommandType.Text, SqlComm);

        //FILEService.FILEService wsProxy = new MonArch610.WebSite.FILEService.FILEService();
        //FILEService.XDFILE XDFILE = new MonArch610.WebSite.FILEService.XDFILE();

        //wsProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
        //wsProxy.Url = System.Configuration.ConfigurationSettings.AppSettings["BPM Server"] + "BZService/FILEService.asmx";
        //XDFILE = wsProxy.FileDownload(PIN);
        byte[] bb = (byte[])ds.Tables[0].Rows[0]["FILEDATA"];

        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["FILENAME"].ToString()));
        HttpContext.Current.Response.ContentType = ds.Tables[0].Rows[0]["FILECONTENTTYPE"].ToString();
        HttpContext.Current.Response.OutputStream.Write(bb, 0, bb.Length);
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.End();
    }
}